package View.GeneralManagerView.VariablePanel;

import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;

import javax.swing.JTextField;

public class numberTextField extends JTextField implements InputFieldWithDefaultValue{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	String text;
	
	public numberTextField(){
		super();
		this.addFocusListener(new FocusListener() {
			
			@Override
			public void focusLost(FocusEvent e) {
				judgeNum();
				
			}
			
			@Override
			public void focusGained(FocusEvent e) {
			
			}
		});
	}
	

	
	private void judgeNum(){
		for(int i=0;i<this.getText().length();i++){
			if(this.getText().charAt(i)>'9' || this.getText().charAt(i)<'0'){
					this.setText("");
			}
		}
	}



	@Override
	public Object getFillingIn() {
		if(this.getText().equals(""))
			return null;
		else
			return Integer.valueOf(this.getText());
	}



	@Override
	public String getFormatClassName() {
		return this.getClass().getName();
	}



	@Override
	public void setDefaultValue(String x) {
		this.setText(x);
	}
}
